import React from 'react'
// ===================================================================== Temp
import SearchForm from '#cpt/temp/SearchForm'
import Table from '#cpt/temp/Table'
import AddEditModal from '#cpt/temp/AddEditModal'
import TableControls from '#cpt/temp/TableControls'
import Controls from '#cpt/temp/Controls'
import Confirm from '#cpt/temp/Confirm'
// ===================================================================== global declare
const { $fn, $Lazy } = window
// ===================================================================== Lazy
const Page 					= $Lazy.load(()=>import('#tp/page/page-container'))
// ===================================================================== component
class Index extends React.Component{
	state = {
		data:[],
		pag: {},
		// 搜索表单列表
		forms : [
			{ label: '编号',		name: 'code' },
		],
		// 提交表单列表
		formData : [
			{ label: '名称',		name: 'name', 	 	half:true, 		required:true },
			{ label: '编号',		name: 'code', 		half:true, 		required:true, disabled:true },
			{ label: '内容',		name: 'content', 	full:true,      type:'textarea' },
			{ label: '备注',		name: 'remark', 	full:true,		type:'textarea' },
		],
	}
	
	model = {}
	
	componentDidMount(){
		this.fetch()
	}
	
	// paging
	fetch = () => $fn.fetch.call(this,'settings-source/index',{isIndex:true})
	
	// 表单
	cols = [
		{ title: '编号',		dataIndex: 'code', 		width:50 },
		{ title: '名称', 	dataIndex: 'name', 		width:150 },
		{ title: '内容', 	dataIndex: 'content', 	width:150 },
		{ title: '备注', 	dataIndex: 'remark', 	width:150 },
		TableControls.controls.call(this)
	]
	// 表格操作按钮
	table_controls = (text,{ id }) => {
		return [
			TableControls.edit.call(this, 'settings-source/info', { id },{idStr:'id', nameStr:'id'} ),				// 编辑
		]
	}
	// 操作按钮
	controls = () => {
		return [
			Controls.add.call(this),			// 添加
			// 清除缓存
			Confirm.call(this, '清除缓存', 'settings-source/clearcache',{ ghoust:true } )
		]
	}
	
	render(){
		return (
			<>
				<Page title='系统配置-源配置' controls={this.controls()}>
					{/* 搜索 */}
					{ SearchForm.call(this) }
					{/* 表格 */}
					{ Table.call(this,{isIndex:true}) }
				</Page>
				{/* 添加、编辑 */}
				{ AddEditModal.call(this,{ api: 'settings-source/add', editApi:'settings-source/edit' }) }
			</>
		)
	}
}

export default Index